package com.android.hedgehog;

import java.util.List;

import android.graphics.Color;

import com.android.hedgehog.framework.Game;
import com.android.hedgehog.framework.Graphics;
import com.android.hedgehog.framework.Screen;
import com.android.hedgehog.framework.Input.TouchEvent;

public class TesterScreen extends Screen {
	String lines[] = new String[5];
	int score = 0;
	String linePuzzles[][] = new String[Settings.totalPuzzles][5];
	String lineRounds[] = new String[Settings.totalRounds];
	String data1, data2;
	int puzzleNumber = 0;

	public TesterScreen(Game game) {
		super(game);
		loadCurrentGameScores();

	}

	@Override
	public void update(float deltaTime) {
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		game.getInput().getKeyEvents();

		int len = touchEvents.size();
		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_UP) {
				if (event.y > 352 && event.y < 418) {// 1-5
					if (event.x < 64) {
						// Settings.save(game.getFileIO());
					}
					if (event.x > 64 && event.x < 128) {
						Settings.isMale = !Settings.isMale;
					}
					if (event.x > 128 && event.x < 192) {
						Settings.age = score;
					}
					if (event.x > 192 && event.x < 256) {
					}
					if (event.x > 256 && event.x < 320) {
					}
				}// 1-5
				if (event.y > 418) {// 6-10
					if (event.x < 64) {
						game.setScreen(new MainMenu2(game));
					}
					if (event.x > 64 && event.x < 128) {
						Settings.load(game.getFileIO());
						loadCurrentGameScores();
					}
					if (event.x > 128 && event.x < 192) {
						score += 5;
					}
					if (event.x > 192 && event.x < 256) {
						puzzleNumber++;
						if (puzzleNumber == 15)
							puzzleNumber = 0;
					}
					if (event.x > 256 && event.x < 320) {
						// Settings.addScore(puzzleNumber, score);
					}
				}// 6-10

			}
		}

		lines[0] = "score: " + score;
		lines[1] = " puzzle#: " + puzzleNumber;

	}

	private void loadCurrentGameScores() {
		for (int i = 0; i < Settings.totalPuzzles; i++) {
			for (int j = 0; j < 5; j++) {
				if (j == 0)
					linePuzzles[i][j] = "Game" + i + ": "
							+ Settings.highScores[i][j];
				else
					linePuzzles[i][j] = " " + Settings.highScores[i][j];
			}
		}
		lineRounds[0] = "rScore: " + Settings.roundScores[0];
		for (int i = 1; i < Settings.totalRounds; i++) {
			lineRounds[i] = " " + Settings.roundScores[i];
		}

		data1 = "name: " + Settings.userName + " Age: " + Settings.age
				+ " male: " + Settings.isMale + " OnLev: " + Settings.round;
		data2 = "CScore: " + Settings.cyberScore + " CRank: "
				+ Settings.globalRank+ " IQ: " + Settings.iqRating;

	}
	@Override
	public void present(float deltaTime) {
		Graphics g = game.getGraphics();
		g.drawPixmap(Assets.blackbackground, 0, 0);
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 310; j = j + 64) {
				g.drawRect2(j, 352 + (i * 64), 64, 64, Color.GRAY);
			}
		}
		g.drawText("main......load.......score+.....puzzle+....addScore", 160,
				470, 16, Color.WHITE);
		g.drawText("save.....flipG....ageChange............................",
				160, 410, 16, Color.WHITE);
		for (int i = 0; i < Settings.totalPuzzles; i++) {
			for (int j = 0; j < 5; j++) {
				g.drawText(linePuzzles[i][j], 50 + (j * 50), 30 + (i * 15), 14,
						Color.WHITE);
			}
		}
		for (int i = 0; i < Settings.totalRounds; i++) {
			g.drawText(lineRounds[i], 40 + (i * 30), 180, 12, Color.WHITE);
		}
		g.drawText(data1, 160, 215, 14, Color.WHITE);
		g.drawText(data2, 160, 235, 14, Color.WHITE);
		// g.drawText(lines[0], 50, 335, 14, Color.WHITE);// score
		// g.drawText(lines[1], 130, 335, 14, Color.WHITE);

	}
	@Override
	public void pause() {

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}
